package com.foreknow.view;

import com.foreknow.bean.Guestbook;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

public class Selectjieguoji extends JFrame {

	private JPanel contentPane;
	private JTable table;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Selectjieguoji frame = new Selectjieguoji();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Selectjieguoji() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel label = new JLabel("\u67E5\u8BE2\u7ED3\u679C");
		label.setBounds(181, 21, 158, 27);
		contentPane.add(label);
		table = new JTable();


		List<Object> l = new ArrayList<>();
		l.add(Select.guestbook);
		String[] columnNames =
				{ "id", "name", "phone", "email", "title", "content", "createdtime" };
		Object[][] obj = new Object[ l.size()][7];
		for (int i = 0; i < l.size(); i++)
		{
			Guestbook guestbook = (Guestbook) l.get(i);
			for (int j = 0; j < 7; j++)
			{
				switch (j)
				{
					case 0:
						obj[i][j] = guestbook.getId();
						break;
					case 1:
						obj[i][j] = guestbook.getName();
						break;
					case 2:
						obj[i][j] = guestbook.getPhone();
						break;
					case 3:
						obj[i][j] = guestbook.getEmail();
						break;
					case 4:
						obj[i][j] = guestbook.getTitle();
						break;
					case 5:
						obj[i][j] = guestbook.getContent();
						break;
					case 6:
						obj[i][j] = guestbook.getCreatedtime();
						break;
				}
			}
		}
		table = new JTable(obj,columnNames);
		table.setBounds(75, 69, 308, 86);
		contentPane.add(table);
		this.setVisible(true);
		JButton button = new JButton("\u8FD4\u56DE");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				MainWindow mainWindow = new MainWindow();
				Selectjieguoji.this.dispose();
			}
		});
		button.setBounds(167, 193, 93, 23);
		contentPane.add(button);
		this.setVisible(true);
	}
}